#include<bits/stdc++.h>
using namespace std;
struct fsh{
	int b , f;
	string n;
};
bool cmp(fsh fsh1 , fsh fsh2){
	if(fsh1.f != fsh2.f){
		return fsh1.f > fsh2.f;
	}
	else{
		if(fsh1.n != fsh2.n){
			return fsh1.n < fsh2.n;
		}
		else{
			return fsh1.b < fsh2.b;
		}
	}
}
int main(){
	freopen("sheet.in" , "r" , stdin);
	freopen("sheet.out" , "w" , stdout);
	int n;
	cin >> n;
	fsh s[45];
	for(int i = 1 ; i <= n ; i++){
		cin >> s[i].n >> s[i].f;
		s[i].b = i;
	}
	sort(s + 1 , s + n + 1 , cmp);
	for(int i = 1 ; i <= min(n , 10) ; i++){
		cout << s[i].b << " " << s[i].n <<" " << s[i].f << endl;
	}
	return 0;
} 
